<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/resource/css/assets/bootstrap.min.css" rel="stylesheet"/>
    <link href="/resource/css/style.css" rel="stylesheet"/>
    <link href="/resource/css/assets/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/resource/css/assets/ace.min.css"/>
    <link rel="stylesheet" href="/resource/font/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/resource/css/assets/ace-ie.min.css"/>
    <![endif]-->
    <script src="/resource/js/jquery-1.9.1.min.js"></script>
    <script src="/resource/js/assets/bootstrap.min.js"></script>
    <script src="/resource/js/assets/typeahead-bs2.min.js"></script>
    <script src="/resource/js/dragDivResize.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="/resource/js/JQuery-zTree-v3.5.15/css/zTreeStyle/zTreeStyle.css">
    <title>添加权限</title>
</head>

<body>
<div class="Competence_add_style clearfix">
    <div class="left_Competence_add">
        <div class="Competence_add">
            <!--按钮操作-->
            <div class="Button_operation">
                <button onclick="getCheckNodes()" class="btn btn-primary radius" type="submit"><i
                        class="fa fa-save "></i> 保存并提交
                </button>
                <button id="close" class="btn btn-default radius" type="button">
                    &nbsp;&nbsp;取消&nbsp;&nbsp;
                </button>
            </div>
        </div>
    </div>
    <!--权限分配-->
    <div class="Assign_style">
        <div class="Select_Competence">
            <ul id="treeDemo" class="ztree" style=" overflow:auto;"></ul>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    //初始化宽度、高度
    $(".left_Competence_add,.Competence_add_style").height($(window).height()).val();
    ;
    $(".Assign_style").width($(window).width() - 500).height($(window).height()).val();
    $(".Select_Competence").width($(window).width() - 500).height($(window).height() - 40).val();
    //当文档窗口发生改变时 触发
    $(window).resize(function () {

        $(".Assign_style").width($(window).width() - 500).height($(window).height()).val();
        $(".Select_Competence").width($(window).width() - 500).height($(window).height() - 40).val();
        $(".left_Competence_add,.Competence_add_style").height($(window).height()).val();
        ;
    });

</script>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript" src="/resource/js/JQuery-zTree-v3.5.15/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">

    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            form = layui.form;

        $('.btn-default').on('click', function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        })

    });

</script>
<script LANGUAGE="JavaScript" th:inline="javascript">
    var zTreeObj;
    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
    var setting = {
        check: {
            enable: true,
        },
        view: {
            showLine: true, //显示辅助线
            dblClickExpand: true,
        },
        data: {enable: true},
    };
    // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
    console.log([[${sysList}]])
    var zNodes = [[${sysList}]];

    $(document).ready(function () {
        zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    });

    //保存
    function getCheckNodes() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo"),
            nodes = treeObj.getCheckedNodes(true);
        var dataNodes = "";
        for (var i = 0; i < nodes.length; i++) {
            dataNodes += nodes[i].id + ",";
        }
        console.log(dataNodes); //获取选中节点的值
        addPermission(dataNodes)
    }

    //角色授权方法
    function addPermission(ids) {
        $.ajax({
            url: "/role/accredit.do",
            type: "post",
            data: {"permissionsIds": ids, "id": [[${role.id}]]},
            dataType: "json",
            success: function (result) {
                if (!result.status) {
                    layer.msg(result.msg, {time: 2000});
                    return false;
                }
                parent.$.messager.alert("提示", "操作成功!", "info");
            }
        });
        parent.layer.close(parent.layer.getFrameIndex(window.name));

    }
</script>